package org.catspaw.cherubim.persistence.hibernate;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class OpenSessionInViewFilter implements Filter {

	public void destroy() {
	}

	public void doFilter(ServletRequest servletRequest,
			ServletResponse servletResponse, FilterChain chain)
			throws IOException, ServletException {
		try {
			SessionManager.getInstance().getSession();
			chain.doFilter(servletRequest, servletResponse);
		} finally {
			SessionManager.getInstance().closeCurrentSession();
		}
	}

	public void init(FilterConfig config) throws ServletException {
	}
}
